//
//  ByMyVC.m
//  mijifen_ios
//
//  Created by mc on 2017/10/20.
//  Copyright © 2017年 itboye. All rights reserved.
//

#import "ByMyVC.h"

// view
#import "ByViewMyHeader.h"

//
#import "ByModelUser.h"

// vc
#import "ByLoginVC.h"
#import "ByMyCollectCodeVC.h"

// cell
#import "ByCellMy.h"

@interface ByMyVC ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView           *tableView;
@property (nonatomic, strong) ByViewMyHeader        *headerView;
@property (nonatomic, strong) UIButton              *bottomButton;

@property (nonatomic, copy)   NSArray               *titles;
@property (nonatomic, copy)   NSArray               *images;
@property (nonatomic, copy)   NSArray               *rightImgs;
@end

@implementation ByMyVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"我的";
    self.view.backgroundColor = BY_TABLE_COLOR;
    [self createBottomView];
    [self initTable];
}

#pragma mark - getter
- (NSArray *)titles{
    if (!_titles) {
        _titles = @[@"店铺收款码",@"提示音开关"];
    }
    return _titles;
}

- (NSArray *)images{
    if (!_images) {
        _images = @[@"mine_collect_code",@"mine_sound"];
    }
    return _images;
}

- (NSArray *)rightImgs{
    if (!_rightImgs) {
        _rightImgs = @[@"mine_arrow",@""];
    }
    return _rightImgs;
}

#pragma mark - 创建视图
- (void)initTable{
    _headerView = [[ByViewMyHeader alloc] init];
    [self.view addSubview:_headerView];
    [_headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        if (@available(iOS 11.0,*)) {
        
            make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
        }else{
            make.top.equalTo(self.view).offset(0);
        }
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 170));

    }];
    ByModelUser *user = [[ByModelUser alloc] init];
    user.name = @"佳慧超市";
    _headerView.user = user;
    
    _tableView = [[UITableView alloc] init];
    [self.view addSubview:_tableView];
    _tableView.backgroundColor = BY_TABLE_COLOR;
    _tableView.separatorColor = [UIColor colorWithWhite:0.90 alpha:1];
    _tableView.separatorInset = UIEdgeInsetsMake(39, 10, 0, -10);
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        if (@available(iOS 11.0, *)) {
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-49 - 60);
            make.left.equalTo(self.view.mas_safeAreaLayoutGuideLeft);
            make.right.equalTo(self.view.mas_safeAreaLayoutGuideRight);
        }else{
            make.bottom.equalTo(self.view.mas_bottom).offset(- 49 - 60);
            make.left.equalTo(self.view.mas_left);
            make.right.equalTo(self.view.mas_right);
        }
        make.top.equalTo(_headerView.mas_bottom);
    }];
    
    _tableView.delegate = self;
    _tableView.dataSource = self;
}

- (void)createBottomView{
     _bottomButton = [[UIButton alloc] init];
    [_bottomButton setTitle:@"退出登陆" forState:UIControlStateNormal];
    [_bottomButton setBackgroundColor:BY_THEME_COLOR];
    [_bottomButton setTitleColor:BY_TEXT_COLOR forState:UIControlStateNormal];
    [_bottomButton addTarget:self action:@selector(quitAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:_bottomButton];

    [_bottomButton mas_makeConstraints:^(MASConstraintMaker *make) {
        if (@available(iOS 11.0, *)) {
            make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(- 49 - 10);
        } else {
            make.bottom.equalTo(self.view.mas_bottom).offset(- 49 - 10);
        }
        make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 50));

    }];
}

#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    ByCellMy *cell = [ByCellMy cellWithTableView:tableView andTitle:self.titles[indexPath.row] andLeftImg:self.images[indexPath.row] andRightImg:self.rightImgs[indexPath.row]];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return [UIView new];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        ByMyCollectCodeVC *vc = [[ByMyCollectCodeVC alloc] init];
        [self by_normalPush:vc hasNavi:YES];
    }
}
#pragma mark - 退出
- (void)quitAction{
    UIWindow *window = [UIApplication sharedApplication].keyWindow;
    ByBaseNaviController *navi = [[ByBaseNaviController alloc] initWithRootViewController:[[ByLoginVC alloc] init]];
    window.rootViewController = navi;
}


@end
